// ADOCommand.cpp: implementation of the CADOCommand class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ADOCommand.h"
 
#include "adoDatabase.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif 
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CADOCommand::CADOCommand()
{
	m_pCommand = NULL;
	m_padoDB = NULL;
}

CADOCommand::~CADOCommand()
{

}

BOOL CADOCommand::Execute(CString sCommand,BOOL bProcedure,BOOL bAsync)
{
	if(m_pCommand == NULL)
	{
		HRESULT hr;
		hr = m_pCommand.CreateInstance(__uuidof(Command));
		if(FAILED(hr))
		{
			m_pCommand = NULL;
			return FALSE;
		}
		if(m_padoDB != NULL)
			m_pCommand->ActiveConnection = m_padoDB->GetConnection();
	}
	try
	{
		m_pCommand->CommandText = (_bstr_t)sCommand;
		if(bProcedure)
			m_pCommand->CommandType = adCmdStoredProc;
		else
			m_pCommand->CommandType = adCmdText;

		if(bAsync)
			m_pCommand->Execute(NULL,NULL,adAsyncFetch);
		else
			m_pCommand->Execute(NULL,NULL,adCmdText);
	}
	catch(_com_error e)
	{
		//AfxMessageBox(e.Description());
		OutputDebugString(e.Description());
		return FALSE;
	}
	return TRUE;
}

CADOCommand::CADOCommand(CADODatabase *padoDB)
{
	m_padoDB = padoDB;
}
